package frame;

import controle.BackupBD;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Usuario
 */
public class CriarBkpView extends javax.swing.JFrame {

    String caminho = "";

    /** Creates new form BkpView */
    public CriarBkpView() {
        initComponents();
     
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jFileChooser2 = new javax.swing.JFileChooser();
        jFileChooser2.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jLabel1 = new javax.swing.JLabel();

        setTitle("BACKUP BANCO DE DADOS");
        getContentPane().setLayout(null);

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setText("BACKUP");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(350, 250, 190, 30);
        getContentPane().add(jFileChooser2);
        jFileChooser2.setBounds(10, 50, 530, 240);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("SELECIONE A PASTA PARA BACKUP");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(120, 10, 310, 30);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-560)/2, (screenSize.height-327)/2, 560, 327);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed


        
         try {
        
                
             caminho = jFileChooser2.getSelectedFile().getPath();
        
            new BackupBD().cria_bkpbd(caminho + "/tarefas.script");
            JOptionPane.showMessageDialog(null, "Backup realizado em: \n" + caminho + "\tarefas.script");
            this.setVisible(false);


        } catch (Exception e) {

            JOptionPane.showMessageDialog(null, "Selecione uma pasta para backup !");

        }



    }//GEN-LAST:event_jButton1ActionPerformed

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CriarBkpView().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JFileChooser jFileChooser2;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables
}
